<%--
  Created by IntelliJ IDEA.
  User: 老头
  Date: 2023/4/13
  Time: 20:57
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>

</head>

<body>
<%@include file="./include/head.jsp"%>
<%@include file="./include/menu_search.jsp"%>
<form action="Handle-login.jsp" id="Myform" method="post">
    <table>
        <tr>
            <td>用户名：</td>
            <td><input type="text" name="myName" id="myName" /><span>       字母数字下划线1到10位，不能是数字开头</span></td>
        </tr>
        <tr>
            <td>密码：</td>
            <td><input type="password" name="myPassword" id="myPassword" /><span>密码请设置8-16位字符</span></td>
        </tr>

        <%--        <tr>--%>
        <%--            <td><input class="image" type="image" src="./resources/img.png" name="submit" id="btn_add" /></td>--%>
        <%--        </tr>--%>
        <tr>
            <%--           <td class="login"></td>--%>
            <%--nclick="checkForm()" --%>
            <td>
                <%--        <input type="button" value="跳转到2.jsp" οnclick="Two()"      class="botton"/>--%>
            </td>
            <td class="login">  <input type="button" onclick="checkForm()" value="登录">
            </td>
            <%--            <td><input type="submit"></td>--%>
        </tr>
    </table>
</form>
<style>
    form{
        background-color: #fcfdef;
        width: 80%;
        margin: 0 auto;
    }
    table{
        margin: 0 auto;
        padding: 20px 0;

    }

    .login{
        /*margin-left: 50px;*/
        /*padding-left: 100px;*/

    }

</style>
<script type="text/javascript" >
    function Two() {
        document.form.action = "Handle-login.jsp";
        document.form.submit();
    }

    //Handle-login.jsp
    function checkForm() {
        //alert(1)
        //alert(1);
        let Myform=document.getElementById("Myform");
        //Myform.submit();
        let str_exec=/^[a-zA-Z_][a-zA-Z0-9_]{0,9}$/;
        let struser=document.getElementById("myName").value;
        flag=true;
        if(str_exec.test(struser)){
            // console.log("用户名正确");
            //  Myform.submit();
        }else{
            //alert("正确");
            flag=false;
            // console.log("用户名错误");
            alert("用户名格式错误!");
        }
        let pwd_exec=/^[_0-9a-z]{8,16}$/;
        let myPassword=document.getElementById("myPassword").value;
        if(pwd_exec.test(myPassword)){
            //    console.log("用户名正确");
        }else{
            //alert("错误");
            flag=false;
            // console.log("密码错误")
            alert("用户名格式错误!");
        }
        console.log(flag);
        if (flag){
            Myform.submit();
        }
        // document.getElementById("btn_add").onclick = function () {
        //     var name = document.getElementById('myName').value
        //     var password = document.getElementById('myPassword').value
        //     var check = document.getElementById('myPasswordCheck').value
        //     if (check == "") {
        //         alert("请校验你的密码");
        //         return
        //     }
        //     if (password == check) {
        //         // alert("校验了你的姓名：" + name + " 密码：" + password + "符合要求");
        //         window.location.href="Handle-register.jsp"
        //     } else {
        //         alert("输入的两次密码不一样");
        //     }
        // }
    }


</script>
</body>
</html>
